package com.xk.jdbc;

import java.sql.*;

public class JDBC {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        
        try {
            connection = DBUtils.getConnection();
            preparedStatement = connection.prepareStatement("select * from person");
            resultSet = preparedStatement.executeQuery();

            while (resultSet.next()) {
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                int age = resultSet.getInt("age");
                String bornDate = resultSet.getString("bornDate");
                String email = resultSet.getString("email");
                String address = resultSet.getString("address");

                System.out.println(id + "\t" + name + "\t" + age + "\t" + bornDate + "\t" + email + "\t" + address);
            }
        } catch (SQLException e) {
            throw new RuntimeException("数据库操作失败", e);
        } finally {
            try {
                if (resultSet != null) resultSet.close();
                if (preparedStatement != null) preparedStatement.close();
                if (connection != null) connection.close();
            } catch (SQLException e) {
                System.err.println("资源关闭失败: " + e.getMessage());
            }
        }
    }
}